package cn.stylefeng.guns.modular.transport.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.model.params.BasicAddressParam;
import cn.stylefeng.guns.modular.basic.service.BasicAddressService;
import cn.stylefeng.guns.modular.transport.entity.TransportAddressEdit;
import cn.stylefeng.guns.modular.transport.model.params.TransportAddressEditParam;
import cn.stylefeng.guns.modular.transport.model.result.TransportAddressEditResult;
import cn.stylefeng.guns.modular.transport.service.TransportAddressEditService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 地址修改申请表控制器
 *
 * @author zhucx
 * @Date 2023-11-21 10:03:21
 */
@Controller
@RequestMapping("/transportAddressEdit")
public class TransportAddressEditController extends BaseController {

    private String PREFIX = "/transport/transportAddressEdit";

    @Autowired
    private TransportAddressEditService transportAddressEditService;

    @Autowired
    private BasicAddressService basicAddressService;

    @Autowired
    private UserService userService;

    /**
     * 跳转到主页面
     *
     * @author zhucx
     * @Date 2023-11-21
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/transportAddressEdit.html";
    }

    /**
     * 新增页面
     *
     * @author zhucx
     * @Date 2023-11-21
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/transportAddressEdit_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zhucx
     * @Date 2023-11-21
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/transportAddressEdit_edit.html";
    }

    /**
     *批量通过
     * @author zhucx
     * @Date 2023-11-21
     */
    @RequestMapping("/tongguo")
    @ResponseBody
    public ResponseData tongguo(Integer[] ids) {
    	User user = userService.getcurrentUser();
    	for (Integer id : ids) {
    		TransportAddressEdit transportAddressEdit = transportAddressEditService.getById(id);
    		if(transportAddressEdit.getState().equals("待处理")) {
    			BasicAddressParam updateAddressParam = new BasicAddressParam();
    			updateAddressParam.setId(Integer.parseInt(transportAddressEdit.getGetLocationid().toString()));
    			updateAddressParam.setLongitude(transportAddressEdit.getLongitude());
    			updateAddressParam.setLatitude(transportAddressEdit.getLatitude());
    			basicAddressService.update(updateAddressParam);
    			
    			TransportAddressEditParam updateAddressEditParam = new TransportAddressEditParam();
    			updateAddressEditParam.setId(id);
    			updateAddressEditParam.setState("已处理");
    			updateAddressEditParam.setExamineName(user.getName());
    			transportAddressEditService.update(updateAddressEditParam);
    		}
		}
        return ResponseData.success();
    }

    /**
     * 新增接口
     *
     * @author zhucx
     * @Date 2023-11-21
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(TransportAddressEditParam transportAddressEditParam) {
        this.transportAddressEditService.add(transportAddressEditParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author zhucx
     * @Date 2023-11-21
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(TransportAddressEditParam transportAddressEditParam) {
        this.transportAddressEditService.update(transportAddressEditParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author zhucx
     * @Date 2023-11-21
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(TransportAddressEditParam transportAddressEditParam) {
        this.transportAddressEditService.delete(transportAddressEditParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author zhucx
     * @Date 2023-11-21
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(TransportAddressEditParam transportAddressEditParam) {
        TransportAddressEdit detail = this.transportAddressEditService.getById(transportAddressEditParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author zhucx
     * @Date 2023-11-21
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(TransportAddressEditParam transportAddressEditParam,String condition ) {
    	User user = userService.getcurrentUser();
    	transportAddressEditParam.setDeptId(user.getDeptId());
        return this.transportAddressEditService.findPageBySpec(transportAddressEditParam,condition,user.getOperateId());
    }

}


